package git.bds.nyc.framework.file.minio;

import cn.hutool.core.date.DateTime;
import cn.hutool.core.util.IdUtil;
import org.springframework.web.multipart.MultipartFile;

import java.util.Date;

import static git.bds.nyc.constant.Constants.POINT;
import static git.bds.nyc.constant.Constants.SEPARATOR;

/**
 * @author 成大事
 * @since 2023/3/11 16:54
 */
public class MinioFilePath {
    private MinioFilePath(){

    }

    /**
     * 获取上传路径
     *
     * @param file 文件
     * @param id   上传者id
     * @return {@link String}
     */
    public static String getUploadPath(MultipartFile file, Long id, String type){
        //拼接路径
        DateTime dateTime = new DateTime(new Date());
        //获取文件后缀
        String suffix = org.springframework.util.StringUtils.getFilenameExtension(file.getOriginalFilename());
        return id + SEPARATOR + type +
                SEPARATOR + dateTime.year() +
                SEPARATOR + (dateTime.month() + 1) +
                SEPARATOR + dateTime.dayOfMonth() +
                SEPARATOR + IdUtil.getSnowflakeNextId() + POINT + suffix;
    }

    /**
     * 获取头像路径
     *
     * @param file 文件
     * @param id   上传者id
     * @return {@link String}
     */
    public static String getAvatarPath(MultipartFile file,Long id){
        //获取文件后缀
        String suffix = org.springframework.util.StringUtils.getFilenameExtension(file.getOriginalFilename());
        return id + SEPARATOR + "avatar" + SEPARATOR + IdUtil.getSnowflakeNextId() + POINT + suffix;
    }


    /**
     * 获取身份证的路径
     *
     * @param file 文件
     * @param id   上传者id
     * @return {@link String}
     */
    public static String getIdCardPath(MultipartFile file,Long id,int type){
        //获取文件后缀
        String suffix = org.springframework.util.StringUtils.getFilenameExtension(file.getOriginalFilename());
        if(type == 0){
            return id + SEPARATOR + "idCard" + SEPARATOR + id + "-front" + POINT + suffix;
        }
        return id + SEPARATOR + "idCard" + SEPARATOR + id + "-back" + POINT + suffix;
    }

    /**
     * 获取签名路径
     *
     * @param id 上传者id
     * @return {@link String}
     */
    public static String getSignPath(Long id){
        //获取文件后缀
        return id + SEPARATOR + "sign" +
                SEPARATOR + IdUtil.getSnowflakeNextId() + ".png";
    }

    /**
     * 获取订单路径
     *
     * @param sellerId 卖家id
     * @param buyerId  买家id
     * @return {@link String}
     */
    public static String getOrderPath(Long sellerId,Long buyerId){
        //获取文件后缀
        return "order" + SEPARATOR + sellerId + "&&" + buyerId +
                SEPARATOR + IdUtil.getSnowflakeNextId() + ".pdf";
    }
}
